---
description:
  Batteries-included GraphQL Server with focus on easy setup, performance & great developer
  experience
---

import { Tabs } from '@theguild/components'
import CodegenCallout from '../../app/codegen-callout.mdx'

# Quick start

GraphQL Yoga is a batteries-included cross-platform
[GraphQL over HTTP spec-compliant](https://github.com/enisdenjo/graphql-http/tree/master/implementations/graphql-yoga)
GraphQL server powered by [Envelop](https://envelop.dev) and
[GraphQL Tools](https://graphql-tools.com) that runs anywhere; focused on easy setup, performance
and great developer experience.

## Installation

```sh npm2yarn
npm i graphql-yoga graphql
```

## Schema

You will need to provide a schema to Yoga, there are many ways to assemble a GraphQL schema, here's
just a few:

<Tabs items={['graphql-yoga', '@graphql-tools/schema', 'Pothos', 'GraphQL Nexus', 'gqtx', 'graphql-js']}>
  <Tabs.Tab>
Use the `createSchema` function included in Yoga. It actually reuses the [`makeExecutableSchema` from @graphql-tools/schema](https://www.graphql-tools.com/docs/generate-schema).

```js filename="schema.js"
import { createSchema } from 'graphql-yoga'

export const schema = createSchema({
  typeDefs: /* GraphQL */ `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'world'
    }
  }
})
```

<CodegenCallout />

  </Tabs.Tab>

  <Tabs.Tab>
[`makeExecutableSchema` from @graphql-tools/schema](https://www.graphql-tools.com/docs/generate-schema) is very simple, but powerful. Install it and create a schema.

```sh npm2yarn
npm i @graphql-tools/schema
```

```js filename="schema.js"
import { makeExecutableSchema } from '@graphql-tools/schema'

export const schema = makeExecutableSchema({
  typeDefs: /* GraphQL */ `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'world'
    }
  }
})
```

<CodegenCallout />

  </Tabs.Tab>

  <Tabs.Tab>

[Pothos](https://pothos-graphql.dev) is a plugin based GraphQL schema builder for TypeScript.
Install it and create a schema.

```sh npm2yarn
npm i @pothos/core
```

```js filename="schema.js"
import SchemaBuilder from '@pothos/core'

const builder = new SchemaBuilder({})

builder.queryType({
  fields: t => ({
    hello: t.string({
      resolve: () => 'world'
    })
  })
})

export const schema = builder.toSchema()
```

  </Tabs.Tab>

  <Tabs.Tab>
Declarative, Code-First GraphQL Schemas for JavaScript/TypeScript through [Nexus GraphQL](https://nexusjs.org/). Install it and create schema.

```sh npm2yarn
npm i nexus
```

```js filename="schema.js"
import { makeSchema, queryField } from 'nexus'

const helloField = queryField('hello', {
  type: 'String',
  resolve: () => 'world'
})

export const schema = makeSchema({ types: [helloField] })
```

  </Tabs.Tab>

  <Tabs.Tab>
Code-first type-safe GraphQL schema without codegen or metaprogramming using [gqtx](https://github.com/sikanhe/gqtx). Install it and create schema.

```sh npm2yarn
npm i gqtx
```

```js filename="schema.js"
import { buildGraphQLSchema, Gql } from 'gqtx'

const Query = Gql.Query({
  fields: () => [
    Gql.Field({
      name: 'hello',
      type: Gql.String,
      resolve: () => 'world'
    })
  ]
})

export const schema = buildGraphQLSchema({ query: Query })
```

  </Tabs.Tab>

  <Tabs.Tab>
[graphql-js](https://github.com/graphql/graphql-js) is a reference implementation of GraphQL for JavaScript. You should already have it installed, just create schema.

```js filename="schema.js"
import { GraphQLObjectType, GraphQLSchema, GraphQLString } from 'graphql'

export const schema = new GraphQLSchema({
  query: new GraphQLObjectType({
    name: 'Query',
    fields: {
      hello: {
        type: GraphQLString,
        resolve: () => 'world'
      }
    }
  })
})
```

  </Tabs.Tab>
</Tabs>

## Server

After you have created a GraphQL schema, simply pass it in to Yoga and liftoff! 🚀

```js filename="server.js"
import { createServer } from 'node:http'
import { createYoga } from 'graphql-yoga'
import { schema } from './schema.js'

// Create a Yoga instance with a GraphQL schema.
const yoga = createYoga({ schema })

// Pass it into a server to hook into request handlers.
const server = createServer(yoga)

// Start the server and you're done!
server.listen(4000, () => {
  console.info('Server is running on http://localhost:4000/graphql')
})
```

Visit [`http://localhost:4000/graphql`](http://localhost:4000/graphql) to see Yoga in action.
